<!-- annotation Ensuring -->
<template>
  <div>
    <button @click="excute(1000)">
      Ensuring 1s
    </button>
    &nbsp;
    <button @click="excute(2000)">
      Ensuring 2s
    </button>
    &nbsp;
    <button @click="excute(3000)">
      Ensuring 3s
    </button>
    <div>
      result={{ result }}
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component } from "kaygnas-vue-property-decorator";
import { Ensuring } from "@/annotations/ensuring";
import { ErrorIntercept } from "@/annotations/error-intercept";
import sleep from "@/methods/sleep";

@Component({
  name: "Demo12",
})
export default class Demo12 extends Vue {

  public result: number = null;

  @Ensuring()
  public async requestValue(timeout: number) {
    await sleep(timeout);
    return timeout;
  }

  @ErrorIntercept()
  public async excute(timeout: number) {
    this.result = await this.requestValue(timeout);
  }
}
</script>

